genMatrixScale
in GenMath.lib
Matrix Functions Function List by Category Alphabetical Function List
int genMatrixScale(
float *MatrixA, // pointer to
matrix A array
int DimenM,
// number rows in matrix A
int DimenN,
// number columns in matrix A
float Scale,
// scale factor
float *Result)
// pointer to store product Matrix
This function multiples an mxn matrix by a scalar:
Result(i,j) = c * a(i,j)
where c is a scalar. There is no array bounds checking performed within the function; the user must ensure that matrices A, B and C are of proper size. Specifically, all three should be nxn arrays.
The
return code is errno, defined in the C standard library (math.h). This is
an integer value
for math errors.
Sample Application:
/////////// splMScl.c for genMatrixScale Library Function ////////////
// //
// For this sample, 3x3 matrices are used. //
// //
//////////////////////////////////////////////////////////////////////
//////////////////////////// INCLUDES ////////////////////////////////
#include "stdio.h"
#include "genMath.h"
////////////////////////////// MAIN //////////////////////////////////
void main()
{
//local declarations
//integers
int i; // i dimension counter for result
int j; // j dimension counter for result display
int retcode; // return code for call to genMatrixMultnxn
//floats
float a[3][3]; // matrix A
float b[3][3]; // matrix B
float c[3][3]; // resultant matrix, C
//character strings
char ch; //input string to exit
//intialize the A and B matrices
a[0][0] = (float)1.234;
a[0][1] = (float)-.678;
a[0][2] = (float)10.3;
a[1][0] = (float)14.004; a[1][1] = (float)5.332; a[1][2] = (float)0.004;
a[2][0] = (float)-23.400; a[2][1] = (float)0.067; a[2][2] = (float)-3.882; b[0][0] = (float)4.559; b[0][1] = (float)3.24; b[0][2] = (float)0.3422;
b[1][0] = (float)-6.669; b[1][1] = (float)0.076; b[1][2] = (float)13.010;
b[2][0] = (float)2.002;
b[2][1] = (float)1.009;
b[2][2] = (float)-9.007;
//multiply the matrices
retcode = genMatrixMultnxn(a,b,3,c);
//display the result
printf("%s", "Resultant Matrix Elements: \n\n");
for(i=0;i<3;++i){
for(j=0; j < 3; ++j){
printf("%s%d%s%d%s%f%s", "c[",i,"][",j,"] = ",
c[i],"\n");
}
}
//display closing message and wait for <enter> before exiting
printf("\nPress <Enter> to end");
scanf("%c", &ch);
} // End Main
/////////////////////////////// End splMMnn.c ///////////////////////